//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package cn.hutool.extra.expression.engine.spel;

import cn.hutool.extra.expression.ExpressionEngine;

import java.util.ArrayList;
import java.util.Map;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

public class SpELEngine implements ExpressionEngine {
    private final ExpressionParser parser = new SpelExpressionParser();

    public SpELEngine() {
    }

    public Object eval(String expression, Map<String, Object> context) {
        StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
        // 禁用方法调用
        evaluationContext.setMethodResolvers(new ArrayList<>());
        context.forEach(evaluationContext::setVariable);
        return this.parser.parseExpression(expression).getValue(evaluationContext);
    }
}
